<?php

/**
 * html 广告代码调用
 *
 * @create time 2013-3-13
 * @author fishinsky
 */
function htmlCodeShow($ad_id) {
        //为空则非法

        if (empty($ad_id)) {
                return;
        }
        //注意这里 与infoweb调用的不同数据表
        $adModel = M('ad_ad');
        $ret = $adModel->where("id = '" . $ad_id . "'")->find();
        if ($ret['state'] == 0) {
                return;
        }

        //过期广告不显示
        /*  if (time() >= mkDate($ret['enddatetime']) && mkDate($ret['enddatetime']) != '943891200') {
          return;
          } */
        $id = $ad_id;
        $sort = $ret["sort"];
        $content = $ret["content"];
        $adurl = $ret["adurl"];
        $ad_w = $ret["ad_w"];
        $ad_h = $ret["ad_h"];
        $filename = $ret["filename"];
        //$etime = $ret["enddatetime"];
        $state = $ret["state"];
        $ad_content = '';
        if ((int) $sort == 0) {  //文字广告
                $ad_content = "<a href=" . $adurl . " target=_blank><img src=" . "/Public/defualt/images/kong.gif width=" . $ad_w . " height=" . $ad_h . " border=0>" . $content . "</a>\n";
        } else if ((int) $sort == 1) {  //代码广告
                $ad_content .="" . $content . "\n";
        } else if ((int) $sort == 2) {  //图片广告
                $ad_content = "<a href='" . $adurl . "' target='_blank'>";
                $ad_content .="<img src='" . "" . $filename . "' width='" . $ad_w . "' height='" . $ad_h . "' alt='" . $content . "' title='" . $content . "' />";
                $ad_content .="</a>";
        } else if ((int) $sort == 3) {  //FLASH广告
                $ad_content = "<div id=avs style=width:" . $ad_w . "px;height:" . $ad_h . "px;float=left>\n";
                $ad_content .="<div id=avs_1 style=position:absolute;z-index:0>\n";
                $ad_content .="<a href=" . $adurl . " target=_blank><img src=" . "/Public/defualt/images/kong.gif width=" . $ad_w . " height=" . $ad_h . " border=0></a></div>\n";
                $ad_content .="<object classid=clsid:D27CDB6E-AE6D-11CF-96B8-444553540000 id=obj1 codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0 border=0 width=" . $ad_w . " height=" . $ad_h . ">\n";
                $ad_content .="	<param name=movie value=" . $UploadFolder . $filename . ">\n";
                $ad_content .= "	<param name=quality value=High>\n";
                $ad_content .= " <param name=wmode value=transparent>\n";
                $ad_content .= "	<embed src=" . $filename . " pluginspage=http://www.macromedia.com/go/getflashplayer type=application/x-shockwave-flash name=obj1 width=" . $ad_w . " height=" . $ad_h . "></object>\n";
                $ad_content .= "<br/>\n";
                $ad_content .= "</div>)";
        }
        return $ad_content;
}

/**
 * 发送HTTP状态
 * @param integer $code 状态码
 * @return void
 */
function send_http_status($code) {
        static $_status = array(
            // Informational 1xx
            100 => 'Continue',
            101 => 'Switching Protocols',
            // Success 2xx
            200 => 'OK',
            201 => 'Created',
            202 => 'Accepted',
            203 => 'Non-Authoritative Information',
            204 => 'No Content',
            205 => 'Reset Content',
            206 => 'Partial Content',
            // Redirection 3xx
            300 => 'Multiple Choices',
            301 => 'Moved Permanently',
            302 => 'Moved Temporarily ', // 1.1
            303 => 'See Other',
            304 => 'Not Modified',
            305 => 'Use Proxy',
            // 306 is deprecated but reserved
            307 => 'Temporary Redirect',
            // Client Error 4xx
            400 => 'Bad Request',
            401 => 'Unauthorized',
            402 => 'Payment Required',
            403 => 'Forbidden',
            404 => 'Not Found',
            405 => 'Method Not Allowed',
            406 => 'Not Acceptable',
            407 => 'Proxy Authentication Required',
            408 => 'Request Timeout',
            409 => 'Conflict',
            410 => 'Gone',
            411 => 'Length Required',
            412 => 'Precondition Failed',
            413 => 'Request Entity Too Large',
            414 => 'Request-URI Too Long',
            415 => 'Unsupported Media Type',
            416 => 'Requested Range Not Satisfiable',
            417 => 'Expectation Failed',
            // Server Error 5xx
            500 => 'Internal Server Error',
            501 => 'Not Implemented',
            502 => 'Bad Gateway',
            503 => 'Service Unavailable',
            504 => 'Gateway Timeout',
            505 => 'HTTP Version Not Supported',
            509 => 'Bandwidth Limit Exceeded'
        );
        if (isset($_status[$code])) {
                header('HTTP/1.1 ' . $code . ' ' . $_status[$code]);
                // 确保FastCGI模式下正常
                header('Status:' . $code . ' ' . $_status[$code]);
        }
}
function is_gb2312($str) {
	for ($i = 0; $i < strlen($str); $i++) {
		$v = ord($str[$i]);
		if ($v > 127) {
			if (($v >= 228) && ($v <= 233)) {
				if (($i + 2) >= (strlen($str) - 1))
					return true;  // not enough characters  
				$v1 = ord($str[$i + 1]);
				$v2 = ord($str[$i + 2]);
				if (($v1 >= 128) && ($v1 <= 191) && ($v2 >= 128) && ($v2 <= 191)) // utf编码  
					return false;
				else
					return true;
			}
		}
	}
	return true;
}
